<?php
	$listCategoryObj = cri('ListCategory');
	$parentCategories = $listCategoryObj->getParentCategories();
	if(!empty($parentCategories))
	{?>
	<ul class="styled_list">
		<?php
		foreach($parentCategories as $category)
		{
			?>
			<li id = "<?php echo $category['ListCategory']['id']?>">
				<?php echo $appHtml->link($html->image($category['ListCategory']['file_url'],array('alt'=>$category['ListCategory']['name'],'thumb'=>array('crop'=>true,'width'=>16,'height'=>16))),$category['ListCategory']['viewUrl'],array('escape'=>false))?>
				<?php echo $appHtml->link($category['ListCategory']['name'],$category['ListCategory']['viewUrl'],array("title"=>$category['ListCategory']['name']));?>
				<?php echo '('.$listCategoryObj->getListingCount($category).')';?>
			</li>
			<?php 
		}?>
	</ul>
	<?php
	}
?>
<?php 
$updateOrder = false;
if(cr('Modules.moduleEditorMode') == true)
{
	$updateOrder = true;
}
?>
<script type="text/javascript">
$(document).ready(function()
{
	var updateOrder = "<?php echo $updateOrder?>";
	if(updateOrder)
	{
		orders = [];
		$( ".category" ).sortable(
		{
			items: 'li',
			'stop':function(event,li)
			{
				var current_id = li.item.attr('id');
				$('.category li').each(function(index,obj)
				{				
					if(index != "-1")
					{
						id = $(obj).attr('id');
						orders[index] = id;
					}			
				});
				var orderString = orders.join(',');
				$.post(URL+'admin/categories/updateOrder',{'orders':orderString},function(data)
				{
					
				});		
				
			}
		});
	}
});

</script>